<?php

declare(strict_types=1);

namespace App\Controller\MchApi;

use Dotenv\Validator;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\DeleteMapping;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
use App\Exception\XZXValidationException;
use App\Service\ChannelInfoService;
use App\Utils\CustomUtils;
use App\Utils\DateUtils;
use Psr\Container\ContainerInterface;
use Hyperf\Logger\LoggerFactory;
// use App\Middleware\AdminJWTAuthMiddleware;

/**
 * Class ChannelInfoController
 *
 * @package App\Controller
 * @Controller(prefix="/mch/api/channelInfo")
 */
class ChannelInfoController extends MchBaseController {

    /**
     * @Inject()
     * @var ChannelInfoService
     */
    protected $ChannelInfoService;

    /**
     * @var \Psr\Log\LoggerInterface
     */
    protected $logger;

    public function __construct (LoggerFactory $loggerFactory) {
        // 第一个参数对应日志的 name, 第二个参数对应 config/autoload/logger.php 内的 key
        $this->logger = $loggerFactory->get('log', 'default');
    }

    /**
     * 详情
     * @PostMapping(path = "get")
     */
    public function get (RequestInterface $request) {

        $this->_validOrFail($request->all(), [
            'id' => 'required',
        ]);

        $param = [
            'id' => $request->post('id'),
        ];

        return $this->ChannelInfoService->get($param);
    }

    /**
     * 过滤添加/编辑参数
     *
     * @param RequestInterface $request
     *
     * @return array
     */
    protected function _filterEditParam (RequestInterface $request) {

        $param = [
            'channelName'      => $request->post('channelName'),
            'bankId'           => $request->post('bankId'),
            'payType'          => $request->post('payType'),
            'canPay'           => (bool) $request->post('canPay'),
            'canRefund'        => (bool) $request->post('canRefund'),
            'canTransfer'      => (bool) $request->post('canTransfer'),
            'settleCurrency'   => $request->post('settleCurrency'),
            'riskCollectionId' => $request->post('riskCollectionId'),
            'channelType'      => $request->post('channelType'),
            'params'           => $request->post('params'),
            'remark'           => $request->post('remark'),
            'status'           => $request->post('status'),
        ];

        return $param;
    }

    

    /**
     * 列表-下拉框
     * @PostMapping(path = "options")
     */
    public function options (RequestInterface $request) {


        $param = [
            'search'  => $request->post('search', ''),
            'payType' => $request->post('payType', ''),
            'canPay' => $request->post('canPay'),
            'canRefund' => $request->post('canRefund'),
            'canTransfer' => $request->post('canTransfer'),            
        ];

        return $this->ChannelInfoService->options($param);
    }

    /**
     * 支付方式-下拉框
     * @PostMapping(path = "payTypeOptions")
     */
    public function payTypeOptions (RequestInterface $request) {

        $param = [];

        return $this->ChannelInfoService->payTypeOptions($param);
    }

}
